/**
 * @param {number[]} nums
 * @return {number}
 */
 var minimumDeletions = function(nums) {
  const n = nums.length
  let max = Math.max(...nums), min = Math.min(...nums)
  let idx1 = nums.indexOf(max), idx2 = nums.indexOf(min)
  let mid = n >> 1
  if(idx1 <= mid && idx2 <= mid){
    return Math.max(idx1, idx2) + 1
  }
  if(idx1 >= mid && idx2 >= mid){
    return n - Math.min(idx1, idx2)
  }
  if(idx1 <= mid){
    return Math.min(idx2+1, n-idx1, idx1+1 + n-idx2)
  }else{
    return Math.min(idx1+1, n-idx2, idx2+1 + n-idx1)
  }
};